package com.itboye.textileexpres.collection;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.textileexpes.beans.ColletionFenyeBeans;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.util.TimeFormat;
import com.itboye.textileexpres.util.XImageLoader;
import com.itboye.textileexptes.config.GlobalConfig;

public class CollectionGoodsListViewAdapter extends BaseAdapter {
	Context context;
	List<ColletionFenyeBeans.InfoBeans> list = new ArrayList<ColletionFenyeBeans.InfoBeans>();
	boolean flag;
	OnClickListener toTopListener;

	public CollectionGoodsListViewAdapter(Context context,
			List<ColletionFenyeBeans.InfoBeans> list,
			OnClickListener toTopListener) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.list = list;
		this.toTopListener = toTopListener;
	}

	public CollectionGoodsListViewAdapter(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = (LinearLayout) inflater.inflate(
					R.layout.item_goods_collection, null);
			holder.item_goods_lin = (LinearLayout) convertView
					.findViewById(R.id.item_goods_lin);
			holder.publish_time = (TextView) convertView
					.findViewById(R.id.publish_time);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.context = (TextView) convertView.findViewById(R.id.context);
			holder.number = (TextView) convertView.findViewById(R.id.number);
			holder.delete_img = (ImageView) convertView
					.findViewById(R.id.delete_img);
			holder.goods_img = (ImageView) convertView
					.findViewById(R.id.goods_img);
			// holder.checked = (CheckBox)
			// convertView.findViewById(R.id.checked);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.delete_img.setOnClickListener(toTopListener);
		holder.delete_img.setTag(position);
		holder.context.setText(list.get(position).getFavorite_content()
				.getSecondary());
		holder.title
				.setText(list.get(position).getFavorite_content().getName());
		holder.publish_time.setText("时间:"
				+ TimeFormat.DateFormat(list.get(position).getFavorite_content()
						.getExpire_time()));
		XImageLoader.load(GlobalConfig.IMAGE_DOUBLE
				+ list.get(position).getFavorite_content().getId(),
				holder.goods_img);
		holder.number.setText("编号:"
				+ list.get(position).getFavorite_content().getProduct_code());

		return convertView;
	}

	class ViewHolder {
		TextView publish_time, title, context, number;
		LinearLayout item_goods_lin;
		CheckBox checked;
		ImageView goods_img, delete_img;
	}

	
}
